/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.controller;

import cn.hutool.core.util.StrUtil;
import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseDocumentRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseDocumentRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.*;
import com.icinfo.cloud.provider.punish.ucase.punishexecute.dto.DocumentOfUnExecuteQueryDto;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述: 案件文书记录表-TRJ case_document_record 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年02月15日
 */
@RestController
@RefreshScope
@RequestMapping("/punish/ucase/case/main/document/record")
@Slf4j
public class CaseDocumentRecordController extends BaseController {

    @Resource
    private ICaseDocumentRecordService caseDocumentRecordService;


    /**
     * 【V1.0.0】描述：查询案件阶段环节关联文书信息
     *
     * @param queryDto {@link CaseStageLinkRelateDocumentQueryDto}
     * @return {@link Result<  List  <CaseStageLinkRelateDocumentVo>>} 案件阶段环节关联文书信息
     * @author xiangyuyu
     * @date 2022-02-24 14:29
     */

    @PostMapping("/getCaseStageLinkRelateDocumentInfo")
    @ApiOperation(value = "【V1.0.0】描述：查询案件阶段环节关联文书信息", httpMethod = "POST")
    public Result<List<CaseStageLinkRelateDocumentVo>> getCaseStageLinkRelateDocumentInfo(@RequestBody @Validated CaseStageLinkRelateDocumentQueryDto queryDto) {
        List<CaseStageLinkRelateDocumentVo> list = caseDocumentRecordService.getCaseStageLinkRelateDocumentInfo(queryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, list);
    }

    /**
     * 【V1.0.0】描述：根据唯一标识查询文书记录信息
     *
     * @param id 唯一标识
     * @return {@link Result<CaseDocumentRecordVo >} 文书记录信息
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @PostMapping("/getCaseDocumentRecordInfo")
    @ApiOperation(value = "【V1.0.0】描述：根据唯一标识查询文书记录信息", httpMethod = "POST")
    public Result<CaseDocumentRecordVo> getCaseDocumentRecordInfo(@RequestParam String id) {
        CaseDocumentRecordVo vo = caseDocumentRecordService.getCaseDocumentRecordInfo(id);
        return Result.success(Constant.STRING_GET_SUCCESS, vo);
    }

    /**
     * 【V1.0.0】描述：删除文书记录
     *
     * @param caseDocumentRecordDelRequest
     * @return {@link Result< CaseDocumentRecordVo>}
     * @author liyafeng
     * @date 2022/3/1
     */
    @PostMapping("/delCaseDocumentRecordInfo")
    public Result<String> delCaseDocumentRecordInfo(@RequestBody @Validated CaseDocumentRecordDelRequest caseDocumentRecordDelRequest) {
        int num = caseDocumentRecordService.delCaseDocumentRecordInfo(caseDocumentRecordDelRequest);
        if (num < 1) {
            Result.error("删除失败");
        }
        return Result.success("删除成功");
    }

    /**
     * 根据ID删除文书记录
     *
     * @param caseDocumentRecordDelRequest
     * @return {@link Result< CaseDocumentRecordVo>}
     */
    @PostMapping("/delCaseDocumentRecordById")
    public Result<String> delCaseDocumentRecordById(@RequestBody @Validated CaseDocumentRecordDelRequest caseDocumentRecordDelRequest) {
        int num = caseDocumentRecordService.delCaseDocumentRecordById(caseDocumentRecordDelRequest);
        if (num < 1) {
            Result.error("删除失败");
        }
        return Result.success("删除成功");
    }

    /**
     * 描述: 案件需要在浙里办进行操作的文书列表，区分送达地址和签字确认
     *
     * @param dto
     * @return com.icinfo.framework.common.web.Result
     * @author zhanghongqiang
     * @Date 2022/12/5
     */
    @PostMapping("/readCaseDocumentRecordZlb")
    @ApiOperation(value = "【1.7.3】案件需要在浙里办进行操作的文书列表，区分送达地址和签字确认", httpMethod = "POST")
    public Result<PageResponse<CaseDocumentRecordZlbVo>> readCaseDocumentRecordZlb(@RequestBody @Validated CaseDocumentRecordZlbDto dto) {
        List<CaseDocumentRecordZlbVo> vo = caseDocumentRecordService.getCaseDocumentRecordZlb(dto);
        return Result.success(Constant.STRING_GET_SUCCESS,new PageResponse<>(vo));
    }
    /**
     * 【V2.0.0】描述：根据特定信息查询文书关键信息【所有文书通用】
     *
     * @param request {@link DocumentKeyInfoRequest}
     * @return {@link Result<CaseDocumentKeyInfoVo >} 文书关键信息
     * @author xiangyuyu
     * @date 2022-02-16 16:02
     */
    @PostMapping("/getDocumentKeyInfoBySpecialCondition")
    @ApiOperation(value = "【V2.0.0】描述：根据特定信息查询文书关键信息【所有文书通用】", httpMethod = "POST")
    public Result<CaseDocumentKeyInfoVo> getDocumentKeyInfoBySpecialCondition(@Validated @RequestBody DocumentKeyInfoRequest request) {
        CaseDocumentKeyInfoVo vo = caseDocumentRecordService.getDocumentKeyInfoBySpecialCondition(request);
        return Result.success(Constant.STRING_GET_SUCCESS, vo);
    }

    /**
     * 【V2.0.0】描述：查询未执行的处罚决定书列表
     *
     * @return {@link Result< List< CaseDocumentRecordVo>>}
     * @author: zhengqiang
     * @date: 2022/5/31
     * @param: unExecuteFinishQueryDto
     **/
    @PostMapping("/getDocumentRecordOfUnExecute")
    @ApiOperation(value = "【V2.0.0】描述：获取未执行的处罚决定书列表", httpMethod = "POST")
    public Result<List<CaseDocumentRecordVo>> getDocumentRecordOfUnExecute(@RequestBody @Validated DocumentOfUnExecuteQueryDto documentOfUnExecuteQueryDto) {
        List<CaseDocumentRecordVo> list = caseDocumentRecordService.getDocumentRecordOfUnExecute(documentOfUnExecuteQueryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, list);
    }

    /**
     * 【1.3.2】描述：获取文书记录
     *
     * @param dto {@link CaseDocumentRecordDto}
     * @return {@link Result<CaseDocumentRecord>}
     * @author xiangyuyu
     * @date 2022/8/9
     * @since 1.3.2
     */
    @PostMapping("/getCaseDocumentRecord")
    @ApiOperation(value = "【1.3.2】描述：获取文书记录", httpMethod = "POST")
    public Result<CaseDocumentRecord> getCaseDocumentRecord(@RequestBody @Validated CaseDocumentRecordDto dto) {
        String caseId = dto.getCaseId();
        String documentCatalogCode = dto.getDocumentCatalogCode();
        String partyId = dto.getPartyId();
        if (ObjectUtils.isEmpty(caseId)) {
            return Result.error("未指定案件id");
        }
        if (ObjectUtils.isEmpty(documentCatalogCode)) {
            return Result.error("未指定文书目录编码");
        }
        CaseDocumentRecord record = caseDocumentRecordService.getCaseDocumentRecord(caseId, documentCatalogCode, partyId);
        return Result.success(record);
    }

    /**
     * 【1.9.4】描述：专题查询-文书查询
     *
     * @param dto {@link CaseDocumentPageDto}
     * @return {@link Result<PageResponse<PageCaseDocumentVo>>}
     * @author cds
     * @date 2022/12/9
     * @version 1.9.4
     */
    @PostMapping("/pageCaseDocumentRecord")
    @ApiOperation(value = "【1.9.4】描述：专题查询-文书查询", httpMethod = "POST")
    public Result<PageResponse<PageCaseDocumentVo>> pageCaseDocumentRecord(@RequestBody @Validated CaseDocumentPageDto dto){
        List<PageCaseDocumentVo> listResult = caseDocumentRecordService.pageCaseDocumentRecord(dto);
        return Result.success(new PageResponse<>(listResult));
    }
    /**
     * 简案快办修改文书
     * @author liyafeng
     * @date 2023/5/6
      * @param dto
     * @return {@link Result< PageResponse< PageCaseDocumentVo>>}
     */
    @PostMapping("/modFastCaseDocumentRecord")
    public Result<String> modFastCaseDocumentRecord(@RequestBody @Validated ModFastCaseDocumentRecordDto dto){
        int num = caseDocumentRecordService.modFastCaseDocumentRecord(dto);
        if(num>0){
            return  Result.success("修改成功！");
        }
        return Result.error("修改失败！");
    }



}
